home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 733 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.5 KB

  1. From: kanze@gabi-soft.fr (J. Kanze)
  2. Message-ID: <KANZE.96Mar15151356@gabi.gabi-soft.fr>
  3. X-Original-Date: 15 Mar 1996 14:13:56 GMT
  4. Path: in1.uu.net!bounce-back
  5. Date: 15 Mar 96 15:08:14 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: String value of enum
  9. Organization: GABI Software, Sarl.
  10. References: <4i5sf3$89c@hermes.is.co.za> <Do81tp.H9u@rsvl.unisys.com>
  11.     <4i8a38$2qq@engnews1.Eng.Sun.COM> <4i9cn4$7cf@ns.hcsc.com>
  12. In-Reply-To: bill@amber.ssd.hcsc.com's message of 14 Mar 96 16:29:27 GMT
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBFAgUBMUmIFeEDnX0m9pzZAQGlxQF/RwugN9s8NOcLWT1XYZD+bqsUlzZ22WTg
  15.     r56zWV4u+5Wmm0ZEBoo76rWON8vgPnPr
  16.     =fnu7
  17.  
  18. In article <4i9cn4$7cf@ns.hcsc.com> bill@amber.ssd.hcsc.com (Bill
  19. Leonard) writes:
  20.  
  21. |> In article <4i8a38$2qq@engnews1.Eng.Sun.COM>, clamage@Eng.Sun.COM
  22. |> (Steve Clamage) writes:
  23.  
  24. |> > The more general case of non-contiguous enum values could be handled
  25. |> > by a table of value/string pairs and a lookup function. The standard
  26. |> > "map" class will do it all for you.
  27.  
  28. |> But using the map class would require initialization at runtime, wouldn't
  29. |> it?  That increases the startup cost of the program.  Using a sorted array
  30. |> of value/string pairs (statically initialized) and a binary search would
  31. |> probably be more efficient.
  32.  
  33. At start-up, yes.  If the map is large enough for this to make a
  34. difference, however, it's likely that the difference between the O(ln n)
  35. binary search and a O(k) hash table look-up is also significant.
  36.  
  37. Given that the enum labels are all in the source code, and programmers
  38. being on the whole a lazy group of people, the resulting tables are
  39. typically so small that it really doesn't make a difference, especially
  40. since anytime that the conversion is necessary, output will follow.
  41. (I'm still using a linear search in my implementation, and it has yet to
  42. cause a performance bottleneck.)
  43. -- 
  44. James Kanze           (+33) 88 14 49 00          email: kanze@gabi-soft.fr
  45. GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
  46. Conseils, itudes et rialisations en logiciel orienti objet --
  47.               -- A la recherche d'une activiti dans une region francophone
  48. ---
  49. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  50. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  51. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  52. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  53. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  54.